home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / test / test7.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  398 b   |  18 lines  |  [TEXT/R*ch]

  1. abstype 'a Stack =
  2.     EMPTY
  3.   | PUSH of 'a StackTop
  4. withtype 'a StackTop = 'a * 'a Stack
  5. with
  6.   exception EmptyStack;
  7.   val empty = EMPTY;
  8.   fun top EMPTY = raise EmptyStack
  9.     | top (PUSH(x, _)) = x;
  10.   fun push x stack = PUSH(x, stack);
  11.   fun pop EMPTY = raise EmptyStack
  12.     | pop (PUSH(_, rest)) = rest;
  13. end;
  14.  
  15. val st1 = push 3 (push 2 (push 1 empty));
  16. val top1 = top st1;
  17. val rest1 = pop st1;
  18.